package cn.jimmie.lib.qlog.support;

import android.text.TextUtils;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;

/**
 * Func :
 *
 * <p> Create Time:  2019-09-20 10:03 </p>
 * <p> @author Jimmie.Qian  </p>
 */
public class AlFile {
    public static void writeAppend(File file, byte[] buff, int start, int end) {
        if (file == null) return;
        BufferedOutputStream writer = null;
        try {
            writer = new BufferedOutputStream(new FileOutputStream(file, true));
            writer.write(buff, start, end);
            writer.flush();
        } catch (Throwable ignored) {
        } finally {
            AlIO.close(writer);
        }
    }

    public static boolean delete(String filePath) {
        if (TextUtils.isEmpty(filePath)) return true;
        try {
            File f = new File(filePath);
            if (f.exists()) {
                return f.delete();
            }
        } catch (Throwable ignored) {
        }
        return true;
    }

    public static boolean exist(String filePath) {
        if (TextUtils.isEmpty(filePath)) return true;
        File f = new File(filePath);
        return f.exists();
    }
}
